/** 
 * 投保单详情
 */
var insureorderDetailManaged = function() {
	return {
	    formid:"",
        eledata:[],
		initData : function(orderId) {
            insureorderDetailManaged.formid = "actDetailForm";
            $.ajax({
                type: "POST",
                url:ctx + "/insureOrderApply/getone/"+orderId+"?now=" + new Date().getTime(),
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                    insureorderDetailManaged.showelevatortable(data);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    debugger;
                },
            });
		},
		initListener : function() {
		},
        showdialog:function(){
            $("#showDetailDlg").modal("show");
        },
        showelevatortable : function(data){
            var formid = insureorderDetailManaged.formid;
		    var order = data.order;
		    var eledata = data.eles;
            insureorderDetailManaged.eledata = eledata;
            $("#"+formid+" #insureCompany").val(order.insureCompany);
            $("#"+formid+" #insureLinkman").val(order.insureLinkman);
            $("#"+formid+" #insurePhone").val(order.insurePhone);
            $("#"+formid+" #usingUnit").val(order.usingUnit);
            $("#"+formid+" #usingArea").val(order.usingArea);
            $("#"+formid+" #usingAddress").val(order.usingAddress);
            $("#"+formid+" #acceptUnit").val(order.acceptUnit);

            $("#"+formid+" #InsureOrderListTableDetail tbody").html("");
            var totalPremiums = 0;
            $.each(eledata, function(i, n){
                totalPremiums = totalPremiums + n.totalPremium
                var html = '<tr role="row" class="odd" id="tr'+n.id+'">' +
                    '<td>'+(i+1)+'</td>'+
                    // ' <td>'+insureorderDetailManaged.buildnull(n.archiveNo)+'<br/>'+insureorderDetailManaged.buildnull(n.registerCode)+'<br/>'+insureorderDetailManaged.buildnull(n.deviceName)+'<br/>'+insureorderDetailManaged.buildnull(n.deviceType)+'</td>' +
                    // ' <td>'+insureorderDetailManaged.buildnull(n.useDep)+'<br/>'+insureorderDetailManaged.buildnull(n.placeType)+'<br/>'+insureorderDetailManaged.buildnull(n.areaName)
                    //          +'<br/>'+insureorderDetailManaged.buildnull(n.placeAddress)+'<br/>'+insureorderDetailManaged.buildnull(n.deviceUseposition)+'</td>' +
                    // ' <td>'+insureorderDetailManaged.buildnull(n.deviceState)+'<br/>'+insureorderDetailManaged.buildnull(n.superviceState)+'</td>' +
                    // ' <td>'+n.floorNum+'<br/>'+n.doorNum+'<br/>'+n.stationsNum+'<br/>'+n.speed+'</td>' +
                    // ' <td>'+insureorderDetailManaged.buildnull(n.makeCompany)+'<br/>'+insureorderDetailManaged.buildnull(n.installCompany)+'<br/>'+insureorderDetailManaged.buildnull(n.useDep)+'</td>' +
                    // ' <td>'+insureorderDetailManaged.fixeddoubletwo(n.totalPremium)+'</td>' +
                    // ' <td>'+insureorderDetailManaged.buildnull(n.syncDate)+'</td>'+
                    ' <td>'+insureorderDetailManaged.buildnull(n.registerCode)+'</td>' +
                    ' <td>'+insureorderDetailManaged.buildnull(n.deviceName)+'</td>' +
                    ' <td>'+insureorderDetailManaged.buildnull(n.placeType)+'</td>' +
                    ' <td>'+insureorderDetailManaged.buildnull(n.useDep)+'</td>' +
                    ' <td>'+insureorderDetailManaged.buildnull(n.deviceUseposition)+'</td>' +
                    ' <td>'+insureorderDetailManaged.buildnull(n.deviceState)+'</td>' +
                    ' <td>'+insureorderDetailManaged.fixeddoubletwo(n.totalPremium)+'</td>';
                    ' </tr>'
                $("#"+formid+" #InsureOrderListTableDetail tbody").append(html);
            });

            $("#"+formid+" #elenum").html(eledata.length+"台");
            $("#"+formid+" #eleamont").html(insureorderDetailManaged.fixeddoubletwo(totalPremiums)+"元");

            $("#"+formid+" #ordertime").html(new Date(order.startTime).format('yyyy-MM-dd') + " -- " + new Date(order.endTime).format('yyyy-MM-dd'));
        },
		buildnull:function(value){
        	if(value){
        		return value;
			}else{
        		return "";
			}
		},
        fixeddoubletwo:function(value){
            if(value){
                return parseFloat(value).toFixed(2);
            }else{
                return 0;
            }
        }
	};

}();
$(function(){
    insureorderDetailManaged.formid = 'actDetailForm';
    insureorderDetailManaged.initListener();
});
